home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_expansions.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-02-13  |  19.3 KB  |  480 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28.  
  29.  
  30. #include "system_headers.h"
  31.  
  32. APTR BT_ExpPrint,BT_ExpMore,BT_ExpExit;
  33. APTR exptext,explist;
  34. APTR expmoretext0,expmoretext1,expmoretext2,expmoretext3;
  35. APTR expmoretext4,expmoretext5,expmoretext6,expmoretext7;
  36. APTR expmoretext8,expmoretext9,expmoretext10,expmoretext1a;
  37. APTR ExpMoreGroup1,ExpMoreGroup2,ExpMoreAdd1,ExpMoreAdd2;
  38.  
  39. static APTR ExpPool = NULL;
  40.  
  41. __asm __saveds LONG explist_dspfunc(register __a2 char **array, register __a1 struct ExpEntry *expentry, register __a0 struct Hook *hook)
  42. {
  43.  
  44.         if (expentry) {
  45.                 *array++ = expentry->exp_address;
  46.                 *array++ = expentry->exp_boardaddr;
  47.                 *array++ = expentry->exp_type;
  48.                 *array++ = expentry->exp_manufname;
  49.                 *array   = expentry->exp_complete_product;
  50.         } else {
  51.                 *array++ = ESC "bAddress";
  52.                 *array++ = ESC "bBoardAddr";
  53.                 *array++ = ESC "bType";
  54.                 *array++ = ESC "bManufacturer";
  55.                 *array   = ESC "bProduct";
  56.         }
  57.         return(0);
  58. }
  59.  
  60. struct Hook explist_dsphook = {
  61.  {NULL, NULL},
  62.  (ULONG (* )())explist_dspfunc,
  63.  NULL, NULL
  64. };
  65.  
  66. void FreeExpansions (void)
  67. {
  68.     MyFreePoolStructs (&ExpPool, exptext, NULL, explist);
  69. }
  70.  
  71. int GetExpansions (struct ExpEntry **first) {
  72.    struct       ConfigDev      *cd = NULL;
  73.         struct  ExpEntry                        *expentry,*previous = NULL;
  74.  
  75.    int expcnt = 0;
  76.    *first = 0;
  77.  
  78.    if (!ExpPool) ExpPool = tbCreatePool(MEMF_CLEAR, 4096, 4096);
  79.  
  80.    if (clientstate) {
  81.       if (SendDaemon ("GetExpList")) {
  82.  
  83.          while ((expentry = tbAllocPooled(ExpPool, sizeof(struct ExpEntry))) \
  84.            && (ReceiveDecodedEntry ((UBYTE *) expentry, sizeof (struct ExpEntry)))) {
  85.             IsHex (expentry->exp_address, (long *) &expentry->exp_adr);
  86.  
  87.             if (! *first)
  88.                *first = expentry;
  89.             if (previous)
  90.                previous->exp_next = expentry;
  91.  
  92.             expcnt++;
  93.             previous = expentry;
  94.          }
  95.       }
  96.    } else {
  97.         while ((cd = FindConfigDev (cd, -1, -1)) && (expentry = tbAllocPooled(ExpPool, sizeof(struct ExpEntry)))) {
  98.          if (! *first)
  99.             *first = expentry;
  100.          if (previous)
  101.             previous->exp_next = expentry;
  102.    
  103.             expentry->exp_adr = cd;
  104.             _sprintf (expentry->exp_address, "$%08lx", cd);
  105.             _sprintf (expentry->exp_flags, "$%02lx ", cd->cd_Flags);
  106.             _sprintf (expentry->exp_boardaddr, "$%08lx", cd->cd_BoardAddr);
  107.             _sprintf (expentry->exp_boardsize, "$%08lx", cd->cd_BoardSize);
  108.             _sprintf (expentry->exp_type, "$%02lx ", cd->cd_Rom.er_Type);
  109.             _sprintf (expentry->exp_product, "%02lx", cd->cd_Rom.er_Product);
  110.             _sprintf (expentry->exp_manufacturer, "%04lx", cd->cd_Rom.er_Manufacturer);
  111.             _sprintf (expentry->exp_serialnumber, "%lu", cd->cd_Rom.er_SerialNumber);
  112.  
  113.             if(IdentifyBase) {
  114.               IdExpansionTags(IDTAG_ConfigDev,cd,
  115.                               IDTAG_ManufStr ,expentry->exp_manufname,
  116.                               IDTAG_ProdStr  ,expentry->exp_prodname,
  117.                               IDTAG_ClassStr ,expentry->exp_prodclass,
  118.                               IDTAG_Localize ,FALSE,
  119.                               TAG_DONE);
  120.             } else {
  121.                strcpy(expentry->exp_manufname,"no identify.library");
  122.                strcpy(expentry->exp_prodname,"???");
  123.                expentry->exp_prodclass[0] = '\0';
  124.             }
  125.  
  126.             _sprintf (expentry->exp_complete_product,"%s %s",expentry->exp_prodname, expentry->exp_prodclass);
  127.  
  128.          expcnt++;
  129.          previous = expentry;
  130.       }
  131.    }
  132.    return (expcnt);
  133. }
  134.  
  135. void PrintExpansions (char *filename) {
  136.    int   i=1;
  137.    BPTR  handle;
  138.    struct ExpEntry *entryp = NULL;
  139.  
  140.    handle = HandlePrintStart (filename);
  141.    if (handle) {
  142.       if (! WI_Expansions) {
  143.          i = GetExpansions (&entryp);
  144.       }
  145.  
  146.       strcpy (tmpstr, "\n  Address  Flags BoardAddr BoardSize Type Manuf. Prod. Serial#\n");
  147.  
  148.       if (PrintOneLine (handle, tmpstr) && i) {
  149.          for (i=0;;i++) {
  150.             if (WI_Expansions)
  151.                DoMethod (explist,MUIM_List_GetEntry,i,&entryp);
  152.             if (!entryp) break;
  153.  
  154.             _sprintf(tmpstr,"%s · %s %s",entryp->exp_manufname,entryp->exp_prodname,entryp->exp_prodclass);
  155.             _sprintf(tmpstr2, "\n %s  %s %s %s  %s  %s   %s %9s\n Board = %s\n", entryp->exp_address, entryp->exp_flags, entryp->exp_boardaddr, entryp->exp_boardsize, entryp->exp_type, entryp->exp_manufacturer, entryp->exp_product, entryp->exp_serialnumber, tmpstr);
  156.             if (! (PrintOneLine (handle, tmpstr2)))
  157.                break;
  158.  
  159.             if (! WI_Expansions)
  160.                entryp = entryp->exp_next;
  161.          }
  162.       }
  163.    }
  164.    HandlePrintStop();
  165. }
  166.  
  167. void ShowExpansions (void) {
  168.         struct  ExpEntry    *exp;
  169.  
  170.         ApplicationSleep();
  171.         set(explist,MUIA_List_Quiet,TRUE);
  172.         set(BT_ExpMore, MUIA_Disabled, TRUE);
  173.  
  174.         FreeExpansions();
  175.         GetExpansions (&exp);
  176.  
  177.         while (exp) {
  178.            InsertBottomEntry (explist, (APTR *) &exp);
  179.            exp = exp->exp_next;
  180.         }
  181.  
  182.         AwakeApplication();
  183.         set(explist,MUIA_List_Quiet,FALSE);
  184. }
  185.  
  186. void SendExpList (void) {
  187.         struct  ExpEntry    *exp;
  188.  
  189.    FreeExpansions();
  190.    GetExpansions (&exp);
  191.  
  192.    while (exp) {
  193.     SendEncodedEntry ((UBYTE *) exp, sizeof (struct ExpEntry));
  194.     exp = exp->exp_next;
  195.    }
  196.    FreeExpansions();
  197. }
  198.  
  199. void GetExpansionMore (struct ConfigDev *exp) {
  200.         unsigned char     *title = "EXPANSION: ";
  201.         struct  WinFree   *ptr;
  202.         struct  DiagArea  *diag;
  203.         int               i;
  204.         UBYTE             ibyte,flags,type;
  205.  
  206.         UWORD   cdflags[]      = {CDF_SHUTUP, CDF_CONFIGME, CDF_BADMEMORY, CDF_PROCESSED, 0};
  207.  
  208.         char    *cdtext[]      = {"SHUTUP","CONFIGME", "BADMEMORY","PROCESSED"};
  209.  
  210.         UBYTE   ertype[]       = {ERTF_MEMLIST,ERTF_DIAGVALID, ERTF_CHAINEDCONFIG,0};
  211.  
  212.         char    *ertypetext[]  = {"MEMLIST","DIAGVALID", "CHAINEDCONFIG"};
  213.  
  214.         UBYTE   erflags[]      = {ERFF_MEMSPACE,ERFF_NOSHUTUP, ERFF_EXTENDED,ERFF_ZORRO_III,0};
  215.  
  216.         char    *erflagstext[] = {"MEMSPACE","NOSHUTUP", "EXTENDED","ZORRO_III"};
  217.  
  218.         char    *z3subsize[]   = {"MATCHING","AUTO","64K","128K","256K","512K","1M","2M","4M", "6M","8M","10M","12M","14M","RESERVED","RESERVED"};
  219.  
  220.         if (ptr = AllocWinFree()) {
  221.                 ptr->wf_Window = (APTR) WindowObject,
  222.  
  223. //              MUIA_Window_SizeGadget, FALSE,
  224.                 MUIA_HelpNode, ExpansionsText,
  225.                 MUIA_Window_ID, MakeDetailID('.','E','X','P'),
  226.                 WindowContents, HGroup,
  227.                         Child, ExpMoreGroup1 = VGroup,
  228.                                 Child, MyLabel2 ("Manufacturer:"),
  229.                                 Child, MyLabel2 ("Product:"),
  230.                                 Child, MyLabel2 ("Class:"),
  231.                                 Child, MyLabel2 ("Address:\nBoardAddr:\nBoardSize:\nReserved03:"),
  232.                                 Child, MyLabel2 ("Flags:"),
  233.                                 Child, MyLabel2 ("er_Type:"),
  234.                                 Child, MyLabel2 ("er_Flags:"),
  235.                         End,
  236.                         Child, ExpMoreGroup2 = VGroup, MUIA_Group_SameWidth, TRUE,
  237.                                 Child, expmoretext0 = MyTextObject(),
  238.                                 Child, expmoretext1 = MyTextObject(),
  239.                                 Child, expmoretext1a = MyTextObject(),
  240.                                 Child, HGroup,
  241.                                         Child, expmoretext2 = MyTextObject2(),
  242.                                         Child, MyLabel ("SlotAddr:\nSlotSize:\nInitDiagVec:\nSerialNumber:"),
  243.                                         Child, expmoretext3 = MyTextObject2(),
  244.                                         Child, MyLabel ("Driver:\nNextCD:\nUnused[4]:\nReserved[4]:"),
  245.                                         Child, expmoretext4 = MyTextObject2(),
  246.                                 End,
  247.             Child, HGroup,
  248.                Child, VGroup, MUIA_Group_SameWidth, TRUE,
  249.                                 Child, expmoretext5 = MyTextObject2(),
  250.                                 Child, expmoretext6 = MyTextObject2(),
  251.                                 Child, expmoretext7 = MyTextObject2(),
  252.                End,
  253.                Child, VGroup, MUIA_Group_SameWidth, TRUE,
  254.                   Child, MyLabel2 (" = "),
  255.                   Child, MyLabel2 (" = "),
  256.                   Child, MyLabel2 (" = "),
  257.                End,
  258.                Child, VGroup, MUIA_Group_SameWidth, TRUE,
  259.                                 Child, expmoretext8 = MyTextObject(),
  260.                                 Child, expmoretext9 = MyTextObject(),
  261.                                 Child, expmoretext10 = MyTextObject(),
  262.                End,
  263.                                 End,
  264.                         End,
  265.                 End, End;
  266.  
  267.                 if (ptr->wf_Window) {
  268.                         MySetContents (expmoretext2, ESC "r$%08lx\n$%08lx\n$%08lx\n$%02lx", exp, exp->cd_BoardAddr, exp->cd_BoardSize, exp->cd_Rom.er_Reserved03);
  269.                         MySetContents (expmoretext3, ESC "r%ld\n%ld\n$%04lx\n%lu", exp->cd_SlotAddr, exp->cd_SlotSize, exp->cd_Rom.er_InitDiagVec, exp->cd_Rom.er_SerialNumber);
  270.                         MySetContents (expmoretext4, ESC "r$%08lx\n$%08lx\n$%08lx\n$%02lx%02lx%02lx%02lx", exp->cd_Driver, exp->cd_NextCD, exp->cd_Unused[4], exp->cd_Rom.er_Reserved0c, exp->cd_Rom.er_Reserved0d, exp->cd_Rom.er_Reserved0e, exp->cd_Rom.er_Reserved0f);
  271.                         MySetContents (expmoretext5, "$%02lx", exp->cd_Flags);
  272.  
  273.                         tmpstr[0] = '\0';
  274.                         i = 0;
  275.                         while (cdflags[i]) {
  276.                                 if (exp->cd_Flags & cdflags[i]) {
  277.                                     if (strlen (tmpstr)) strcat (tmpstr, ", ");
  278.                                     strcat (tmpstr, cdtext[i]);
  279.                                 }
  280.                                 i++;
  281.                         }
  282.                         MySetContents (expmoretext8, nonetest (tmpstr));
  283.  
  284.                         type = exp->cd_Rom.er_Type;
  285.                         flags = exp->cd_Rom.er_Flags;
  286.  
  287.                         MySetContents (expmoretext6, "$%02lx", type);
  288.  
  289.                         tmpstr[0] = '\0';
  290.                         if (ibyte = type & ERT_TYPEMASK) {
  291.                             if (ibyte & ERT_ZORROIII) {
  292.                                 strcat (tmpstr, "ZORROII");
  293.                                 if (!(ibyte & 0x40))
  294.                                         strcat (tmpstr, "I");
  295.                                 strcat (tmpstr, ", ");
  296.                             }
  297.                         }
  298.                         i = 0;
  299.                         while (ertype[i]) {
  300.                                 if (type & ertype[i]) {
  301.                                         strcat (tmpstr, ertypetext[i]);
  302.                                         strcat (tmpstr, ", ");
  303.                                 }
  304.                                 i++;
  305.                         }
  306.  
  307.          { /* MEMSIZE CALCULATION */
  308.             UBYTE memsize;
  309.  
  310.             memsize = type & ERT_MEMMASK;
  311.                         strcat (tmpstr, "MEMSIZE=");
  312.  
  313.             if (flags & ERFF_EXTENDED) {
  314.                if (memsize == 0x07) {
  315.                                 strcpy (tmpstr2, "?");
  316.                } else if (memsize == 0x06) {
  317.                                 strcpy (tmpstr2, "1G");
  318.                } else {
  319.                                 i = (int) (1L<<memsize) * 16;
  320.                                 _sprintf (tmpstr2, "%ldM", i);
  321.                }
  322.             } else {
  323.                         if (memsize == 0x00) {
  324.                                 strcpy (tmpstr2, "8M");
  325.                            } else if (memsize < 0x05) {
  326.                                 i = (int) (1L<<(memsize - 1)) * 64;
  327.                                 _sprintf (tmpstr2, "%ldK", i);
  328.                            } else {
  329.                                 i = (int) (1L<<(memsize - 5));
  330.                                 _sprintf (tmpstr2, "%ldM", i);
  331.                }
  332.             }
  333.                         strcat (tmpstr, tmpstr2);
  334.                         MySetContents (expmoretext9, nonetest (tmpstr));
  335.          }
  336.  
  337.                         MySetContents (expmoretext7, "$%02lx", flags);
  338.  
  339.          tmpstr[0] = '\0';
  340.                         i = 0;
  341.                         while (erflags[i]) {
  342.                                 if (flags & erflags[i]) {
  343.                if (strlen (tmpstr) > 5)
  344.                                                 strcat (tmpstr, ", ");
  345.                                         strcat (tmpstr, erflagstext[i]);
  346.                                 }
  347.                                 i++;
  348.                         }
  349.  
  350.          if (ERT_ZORROIII == type & ERT_TYPEMASK) {
  351.             if (strlen (tmpstr) > 5)
  352.                         strcat (tmpstr, ", ");
  353.             strcat (tmpstr, z3subsize[flags & 0x0f]);
  354.          }
  355.                         MySetContents (expmoretext10, nonetest (tmpstr));
  356.  
  357.                         if (type & ERTF_DIAGVALID) {
  358.                                 DoMethod (ExpMoreGroup1,OM_ADDMEMBER,MyLabel2 ("DiagArea:\nda_Flags:"));
  359.                                 DoMethod (ExpMoreGroup1,OM_ADDMEMBER,MyLabel2 ("da_Config:"));
  360.  
  361.                                 Child, ExpMoreAdd2 = VGroup, MUIA_Group_SameWidth, TRUE,
  362.                                         Child, HGroup,
  363.                                                 Child, expmoretext4 = MyTextObject2(),
  364.                                                 Child, MyLabel ("da_Size:\nda_Name:"),
  365.                                                 Child, expmoretext5 = MyTextObject2(),
  366.                                                 Child, MyLabel ("da_DiagPoint:\nda_BootPoint:"),
  367.                                                 Child, expmoretext6 = MyTextObject2(),
  368.                                         End,
  369.                Child, HGroup,
  370.                                         Child, expmoretext7 = MyTextObject2(),
  371.                   Child, MyLabel2 (" = "),
  372.                                         Child, expmoretext8 = MyTextObject(),
  373.                End,
  374.                                 End;
  375.                                 DoMethod (ExpMoreGroup2,OM_ADDMEMBER,ExpMoreAdd2);
  376.  
  377.                                 diag = (struct DiagArea *) ((char *) exp->cd_BoardAddr + exp->cd_Rom.er_InitDiagVec);
  378.                                 MySetContents (expmoretext4, ESC "r$%08lx\n$%02lx", diag, diag->da_Flags);
  379.                                 MySetContents (expmoretext5, ESC "r$%04lx\n$%04lx", diag->da_Size, diag->da_Name);
  380.                                 MySetContents (expmoretext6, ESC "r$%04lx\n$%04lx", diag->da_DiagPoint, diag->da_BootPoint);
  381.                                 MySetContents (expmoretext7, "$%02lx", diag->da_Config);
  382.  
  383.                                 strcpy (tmpstr, "BUSWIDTH=");
  384.             ibyte = diag->da_Config;
  385.             if (ibyte & DAC_WORDWIDE) {
  386.                strcat (tmpstr, "WORDWIDE");
  387.             } else {
  388.                if (ibyte & DAC_BYTEWIDE)
  389.                   strcat (tmpstr, "BYTEWIDE");
  390.                else
  391.                   strcat (tmpstr, "NIBBLEWIDE");
  392.             }
  393.  
  394.                                 strcat (tmpstr, ", BOOTTIME=");
  395.             if (ibyte & DAC_BINDTIME) {
  396.                strcat (tmpstr, "BINDTIME");
  397.             } else {
  398.                if (ibyte & DAC_CONFIGTIME)
  399.                   strcat (tmpstr, "CONFIGTIME");
  400.                else
  401.                   strcat (tmpstr, "NEVER");
  402.             }
  403.                                 set (expmoretext8, MUIA_Text_Contents, tmpstr);
  404.                         }
  405.  
  406.                         if(IdentifyBase) {
  407.                            IdExpansionTags(IDTAG_ConfigDev,exp,
  408.                                            IDTAG_ManufStr ,tmpstr,
  409.                                            IDTAG_Localize ,FALSE,
  410.                                            TAG_DONE);
  411.                            set (expmoretext0, MUIA_Text_Contents, tmpstr);
  412.  
  413.                            IdExpansionTags(IDTAG_ConfigDev,exp,
  414.                                            IDTAG_ClassStr ,tmpstr,
  415.                                            IDTAG_Localize ,FALSE,
  416.                                            TAG_DONE);
  417.                            set (expmoretext1a, MUIA_Text_Contents, tmpstr);
  418.  
  419.                            IdExpansionTags(IDTAG_ConfigDev,exp,
  420.                                            IDTAG_ProdStr  ,tmpstr,
  421.                                            IDTAG_Localize ,FALSE,
  422.                                            TAG_DONE);
  423.                            set (expmoretext1, MUIA_Text_Contents, tmpstr);
  424.                         } else {
  425.                            set (expmoretext0, MUIA_Text_Contents, "[identify.library required]");
  426.                         }
  427.  
  428.          HandleWindowOpen (ptr, title, tmpstr);
  429.                         HandleWindowClose (ptr);
  430.                 }
  431.         }
  432. }
  433.  
  434.  
  435. char expansions_title[WINDOWTITLELEN];
  436.  
  437. void ExpansionsWindow (BOOL state) {
  438.    if (state) {
  439.       if (WI_Expansions) {
  440.          ShowExpansions();
  441.       } else {
  442.          WI_Expansions = WindowObject,
  443.          MUIA_Window_Title, MyGetWindowTitle (expansions_title, "EXPANSIONS"),
  444.          MUIA_HelpNode, ExpansionsText,
  445.          MUIA_Window_ID, MakeListID('E','X','P','A'),
  446.          WindowContents, VGroup,
  447.             Child, explist = MyListviewObject ("DELTA=8,DELTA=8,DELTA=8,,",&explist_dsphook),
  448.             Child, exptext = MyTextObject(),
  449.             Child, MyVSpace(2),
  450.             Child, HGroup, MUIA_Group_SameSize, TRUE,
  451.                Child, BT_ExpPrint     = KeyButtonA (PrintText,ID_EXPPRINT),
  452.                Child, BT_ExpMore      = KeyButtonA (MoreText ,ID_EXPMORE),
  453.                Child, BT_ExpExit      = KeyButtonA (ExitText ,ID_EXPEXIT),
  454.             End,
  455.          End, End;
  456.  
  457.          DoMethod (AP_Scout,OM_ADDMEMBER,WI_Expansions);
  458.          DoMethod (WI_Expansions,MUIM_Window_SetCycleChain,explist,BT_ExpPrint,BT_ExpMore,BT_ExpExit,NULL);
  459.  
  460.          SetCloseRequest (WI_Expansions,ID_EXPEXIT);
  461.          SetListActive (explist,ID_EXPLV_ACTIVE);
  462.          SetListviewDoubleClick (explist,ID_EXPMORE);
  463.  
  464.          ShowExpansions();
  465.  
  466.          SetWindowOpen (WI_Expansions,explist,ID_EXPEXIT);
  467.       }
  468.    } else if ((! state) && (WI_Expansions)) {
  469.       SetWindowClose (WI_Expansions,TRUE);
  470.  
  471.       FreeExpansions();
  472.  
  473.       DoMethod (AP_Scout,OM_REMMEMBER,WI_Expansions);
  474.       MUI_DisposeObject (WI_Expansions);
  475.       WI_Expansions = NULL;
  476.       explist = NULL;
  477.    }
  478. }
  479.  
  480.